package com.example.administrator.myapplication.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.example.administrator.myapplication.R;
import com.example.administrator.myapplication.adapter.InformationAdapter;
import com.example.administrator.myapplication.base.BaseMainActivity;
import com.example.administrator.myapplication.mode.InformationDataManager;
import com.example.administrator.myapplication.mode.InformationListData;
import com.example.administrator.myapplication.utils.divider.HorizontalDividerItemDecoration;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;


/**
 * 说明：咨询列表
 * 作者： 阳2012; 创建于： 2017/5/14 21:36
 */
public class InformationActivity extends BaseMainActivity implements InformationDataManager.RefreshListener {
    @BindView(R.id.switchRoot)
    RecyclerView switchRoot;
    private ArrayList<InformationListData> mDatas = new ArrayList<>();
    InformationAdapter adapter;

    public static void startUI(Activity activity) {
        Intent intent = new Intent(activity, InformationActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }


    @Override
    public int getContentView() {
        return R.layout.activity_intformaion;
    }


    @Override
    public void initView() {
        super.initView();
        toolbar.setTitle("资讯");

        adapter = new InformationAdapter(this, mDatas);

        mDatas.addAll(InformationDataManager.getData());
        switchRoot.addItemDecoration(new HorizontalDividerItemDecoration.Builder(this).colorResId(R.color.gray).sizeResId(R.dimen.dp_1).build());
        switchRoot.setLayoutManager(new LinearLayoutManager(this));
        switchRoot.setAdapter(adapter);

        InformationDataManager.getInstands().setRefreshListener(this);
    }

    @Override
    public void parseIntent(Intent intent) {

    }

    @Override
    public int currentItem() {
        return 2;
    }

    @Override
    public void refreshCallback(boolean isRefresh) {
        mDatas.clear();
        mDatas.addAll(InformationDataManager.getData());
        adapter.notifyDataSetChanged();

    }

    @OnClick(R.id.floatingActionButton)
    public void onViewClicked() {
        AddInformationActivity.startUI(this);
    }
}
